package com.ls.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ls.entity.Customer;
import com.ls.service.ICustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

import static com.ls.constant.SystemConstants.*;

/**
 * 清除ai短信轮询
 */
@Slf4j
@Component
public class ClearAiSmsTask {
    @Autowired
    private ICustomerService customerService;
    @Scheduled(cron = "${schedule.clearAi.cron}")
    public void clearAiSms(){
        // 查询需要处理的用户
        List<Customer> customersList = customerService.list(new LambdaQueryWrapper<Customer>()
                .eq(Customer::getValidFlag, VALID_TRUE)
        );
        if (customersList == null || customersList.size() == 0 || customersList.isEmpty()) {
            return;
        }
        for (Customer customer : customersList) {
            customer.setAiSmsCount(AI_SMS_NUMBER);
            customerService.updateById(customer);
        }
    }
}
